#!/usr/bin/env pytho      
# -*- coding: utf-8 -*-
# @Author  : junpeng_chen
# @Time    : 2023/8/9 15:18
# @File    : col_and_row
# @annotation    : 用于前端展示答案图表的col和row识别（基于简单规则）

import os
import sys
# 获取父目录的绝对路径
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
# 将父目录添加到sys.path
sys.path.append(parent_dir)
from utils.log import logger
class ColAndRowRegulator:
    def __init__(self):
        pass
    
    def col_and_row(self, sel, measure):
        """
        col字段和row字段的识别（col暂时为空，row中放dimension的id）
        :param prediciton: 模型预测的有效字符串
        :return: 格式化后的操作符和条件字符串元组，以列表形式返回: [(操作符1, 条件值1),(操作符2, 条件值2)]
        """
        col = []
        row = []
        try:
            for item in sel:
                if item['id'] not in measure:
                    row.append(item['id'])
        except Exception as err:
            logger.error("col and row regulator error[{}]: {}".format(type(err), str(err)))
        
        return col,row
    
    

# if __name__ == "__main__":
#     regulator = ColAndRowRegulator()
#     sel = [{
#             "id":"AUGMENTED_DATASET_LEVEL.I8a8ae5ca0178549554951b9501785cefe3f00058.MT_DIMENSION_FIELD.0c2bf3603bcd7cd295e19909c11b78fe-LEVEL-1659584084158",
#             "name":"销售区域","type":"STRING","timeLevel":"","member_amout":""},
#             {"id":"AUGMENTED_DATASET_LEVEL.I8a8ae5ca0178549554951b9501785cefe3f00058.MT_DIMENSION_FIELD.affebb66d15867660b4dcd4712c9a7d9-LEVEL-1667896197688",
#             "name":"月","type":"STRING","timeLevel":"month","member_amout":""},
#             {"id":"AUGMENTED_DATASET_MEASURE.I8a8ae5ca0178549554951b9501785cefe3f00058.MT_METRICS.I8aaa80fb01804bb34bb3a22501805f86f82b02c9",
#             "name":"MQL个数","type":"DOUBLE","timeLevel":"","member_amout":""}]
        
#     measure = ["AUGMENTED_DATASET_MEASURE.I8a8ae5ca0178549554951b9501785cefe3f00058.MT_METRICS.I8aaa80fb01804bb34bb3a22501805f86f82b02c9"]
#     res = regulator.col_and_row(sel,measure)
#     print(res)